<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta content="webkit" name="renderer">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <link rel="stylesheet" href="/static/crm/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/crm/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form action="" class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">合同ID</label>
                            <div class="layui-input-inline">
                                <input autocomplete="off" class="layui-input" name="id" type="text">
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">合同编号</label>
                                <div class="layui-input-inline">
                                    <input autocomplete="off" class="layui-input" name="number" type="text">
                                </div>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-primary" lay-filter="data-search-btn" lay-submit
                                    type="submit"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <script id="shenhe" type="text/html">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="audit">审核</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>
<script charset="utf-8" src="https://cdnjs.cloudflare.com/ajax/libs/layui/2.7.6/layui.min.js"></script>
<script>
    layui.use(['form', 'table', 'jquery'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/crm/backlog.backlog/one',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left'}
                , {field: 'number', title: '合同编号', width: 120}
                , {field: 'name', title: '合同名称', width: 120}
                , {field: 'client_id', title: '客户名称', width: 120}
                , {field: 'money', title: '合同金额', width: 120}
                , {field: 'remark', title: '备注', width: 90}
                , {field: 'start_time', title: '开始时间', width: 120}
                , {field: 'end_time', title: '结束时间', width: 120}
                , {field: 'sale_id', title: '签约人', width: 100}
                , {field: 'create_time', title: '创建时间', width: 120}
                , {field: 'status', title: '状态', width: 80}
                , {title: '操作', width: 200, toolbar: '#shenhe', fixed: 'right'}
            ]],
            limits: [3, 5, 10],
            limit: 15,
            page: true,
            skin: 'line'
        });


        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            console.log(data.field)
            $.ajax({
                type: 'POST',
                url: '/crm/backlog.backlog/search',
                data: 'id=' + data.field.id + '&number=' + data.field.number,
                dataType: 'json',
                success: function (result) {
                    if (result.msg === '成功') {
                        $('.layui-btn').click(function () {
                            var inputVal = $('.layui-input').val()
                            table.reload('testReload', {
                                url: '/crm/backlog.backlog/search'
                                // ,methods:"post"
                                , request: {
                                    pageName: 'page' //页码的参数名称，默认：page
                                    , limitName: 'limit' //每页数据量的参数名，默认：limit
                                }
                                , where: {
                                    id: result
                                }
                                , page: {
                                    curr: 1
                                }
                            });
                        })
                    } else {
                        layer.msg(result);
                        return false;
                    }
                },
                error: function () {
                    layer.msg('操作失败！！！');
                }
            })
            // console.log(data.field)
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            return false;
        });
        /**
         * toolbar监听事件
         */

        table.on('tool(currentTableFilter)', function (obj) {
            if (obj.event === 'audit') {  // 监听添加操作
                console.log('进入审核')
                layer.open({
                    type: 2,
                    area: ['500px', '600px'],
                    content: '/crm/backlog.audit/dit?id=' + obj.data.id
                })
            }
        });
    });

</script>

</body>
</html>